<%--
  Created by IntelliJ IDEA.
  User: A
  Date: 2024/4/26
  Time: 15:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="../../static/layui/css/layui.css">
    <script src="../../static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/mylayer.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <%--添加form表单--%>

    <form class="layui-form" action="">
        <br>
        <div class="layui-form-item">
            <label class="layui-form-label">汽车型号</label>
            <div class="layui-input-inline layui-input-wrap">
                <select id="carId" name="carId" lay-filter="carId">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名称</label>
            <div class="layui-input-inline layui-input-wrap">
                <select id="userId" name="userId" lay-filter="userId">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">租赁开始时间</label>
            <div class="layui-input-inline layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-date"></i>
                </div>
                <input type="text" name="rentalStartDate" id="rentalStartDate" lay-verify="datetime" placeholder="开始时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">租赁结束时间</label>
            <div class="layui-input-inline layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-date"></i>
                </div>
                <input type="text" name="rentalEndDate" id="rentalEndDate" lay-verify="datetime" placeholder="结束时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="submitAdd">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        layui.use(['form','laydate'], function(){
            var form = layui.form;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#rentalStartDate',
                type: 'datetime'
            });
            laydate.render({
                elem: '#rentalEndDate',
                type: 'datetime'
            });
            $.post(
                '/car?method=selectOrder',
                function (result) {
                    if (result.code == 0) {
                        $(result.data).each(function () {
                            $('#carId').append('<option value="'+this.id+'">'+this.model+'</option>');
                        })
                        form.render('select');
                    }
                },
                'json'
            );
            $.post(
                '/user?method=selectOrder',
                function (result) {
                    if (result.code == 0) {
                        $(result.data).each(function () {
                            $('#userId').append('<option value="'+this.id+'">'+this.username+'</option>');
                        })
                        form.render('select');
                    }
                },
                'json'
            );
            form.on('submit(submitAdd)',function (data) {
                var field = data.field;
                console.log(data);
                $.post(
                    '/order?method=add',
                    field,
                    function (result) {
                        console.log(result);
                        if (result.code == 0) {
                            mylayer.okMsg(result.msg);
                            // layer.close(index);
                            // table.reload('tableId');
                            setInterval(function() {
                                //关闭弹出框
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                //刷新父页面
                                window.parent.location.reload();
                            }, 2000)
                        } else {
                            mylayer.errorMsg(result.msg);
                        }
                    },
                    'json'
                );
                return false;
            });
        });

    </script>
</body>
</html>
